pragma Singleton
import QtQuick
import QtQuick.Window
import "./gameToolKit"

//每把游戏的管理器
QtObject{
    id:root

    //加载一把新游戏，gameComp代表一场游戏的组件
    //initialParam代表传递给游戏的参数
    //返回游戏实例的引用
    function loadGame(gameComp,initialParam = {}){
        var ret = gameComp.createObject(root)
        ret.context = contextComp.createObject(ret)
        ret.context.gameInstance = ret
        ret.context.initialParam = initialParam
        ret.gameStarted()
        return ret
    }

    //结束一场游戏
    function endGame(game){
        game.gameAboutToEnded()
        game.destroy()
    }

    property Component contextComp : Component{
        id:contextComp

        GameContext{
            deviceContext:deviceCtx
        }
    }

    property Component windowComp: Component{
        id:windowComp

        Window{
            visible: true
            height:800
            width: 800

        }
    }

    property Window mainWindow

    property DeviceContext deviceCtx:DeviceContext{
        id:deviceCtx

        Component.onCompleted: {
            mainWindow = windowComp.createObject(root)
            windows.push(mainWindow)
        }
    }

}
